package descentFly.app
{
	import UIFree.controls.uif_loaderBar;
	import UIFree.uif_component;
	import UIFree.uif_ecomponent;
	
	import flash.geom.Rectangle;
	
	public class df_progressBar extends uif_ecomponent {
		private var _bar		: uif_ecomponent;
		private var _percent	: Number;
		
		public function df_progressBar(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0) {
			super(parent, ax, ay, awidth, aheight, 'progressBar');
			var inner: Rectangle = getInner();
			_bar = new uif_ecomponent(this, inner.x, inner.y, inner.width, inner.height, style.bar);
			percent = 0;
		}
		
		public function get percent(): Number {
			return _percent;
		}

		public function set percent(a_percent: Number): void {
			setPercent(a_percent);
		}

		protected function setPercent(a_percent: Number): void {
			if (a_percent != _percent) {
				_percent = (a_percent<=1)?a_percent:1;
				resizeBar();
			}
		}
		
		protected function resizeBar(): void {
			var inner: Rectangle 	= getInner();
			var space: Number 		= getSpace(true) * 2;
			inner.width = space + (inner.width - space) * _percent;
			_bar.style.fill_color = (Math.round(0xFF * (1 - _percent)) << 16) | (Math.round(0xFF * _percent) << 8);
			_bar.resize(inner.width, inner.height);
		}
	}
}